package tools;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Rectangle2D;

import core.DrawContext;
import core.Object2D;

public class RectTool extends GeometricTool {
	
	private RectProxy proxy = new RectProxy();

	@Override
	public void draw(Point p1, Point p2, DrawContext ctx) {
		_draw(p1,p2,ctx.getGraphics());
	}

	@Override
	public Object2D getProxy() {
		return proxy;
	}
	
	private void _draw(Point p1, Point p2, Graphics2D g2){
		
		BasicStroke stroke = new BasicStroke(getLineSize());
		
		g2.setStroke(stroke);
		g2.setColor(getColor());
		
		Rectangle2D.Double ellipse = new Rectangle2D.Double(
				p1.x, p1.y, 
				Math.abs(p1.x - p2.x),
				Math.abs(p1.y - p2.y));
	
		if(isFill()){
			g2.fill(ellipse);
		}
		else{
			g2.draw(ellipse);
		}
	}
	
	private class RectProxy implements Object2D{

		@Override
		public void draw(Graphics2D g2) {
			
			if(!firstSelected){
				return;
			}
			
			_draw(firstPoint, secondPoint, g2);
		}
		
	}


}
